package com.example.homework5;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
	private List<ItemData> itemList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		this.itemList = new ArrayList<ItemData>();

		for (int i = 0; i < 100; i++) {
			ItemData itemData = new ItemData();
			itemData.setTitleText(String.format("Title %d", i));
			itemData.setDescriptionText(String.format("Description %d", i));
			itemData.setImageResourceID(R.drawable.ic_launcher);

			itemList.add(itemData);
		}

		ListView listView = (ListView) this.findViewById(R.id.list1);
		SampleAdapter sampleAdapter = new SampleAdapter(this, this.itemList, SampleAdapter.Type.IMAGE);
		listView.setAdapter(sampleAdapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view, int position,long id) {
				ItemData itemData = (ItemData) adapterView.getItemAtPosition(position);
				Toast.makeText(view.getContext(), itemData.getTitleText(), Toast.LENGTH_SHORT).show();
			}
		});
		
		listView = (ListView) this.findViewById(R.id.list2);
		sampleAdapter = new SampleAdapter(this, this.itemList, SampleAdapter.Type.TEXT);
		listView.setAdapter(sampleAdapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view, int position,long id) {
				ItemData itemData = (ItemData) adapterView.getItemAtPosition(position);
				Toast.makeText(view.getContext(), itemData.getDescriptionText(), Toast.LENGTH_SHORT).show();
			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
